﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;

namespace WordWonderGame.UI
{
    public partial class TimerUI : UserControl
    {
        public TimerUI()
        {
            InitializeComponent();
        }
        public event EventHandler HetGio;
        public event EventHandler LoadCauHoiMoi;
        public int thoiGianHienTai;
        int soCauDung;
        int soCauDungLienTiep;
        int soCauSaiLienTiep;
        int soCauSai;
        public int Diem { get; set; }

        private void lblTime_Click(object sender, EventArgs e)
        {

        }

        private void TimerUI_Load(object sender, EventArgs e)
        {
            thoiGianHienTai = 10;
            timer1.Start();
            picDung1.Visible = false;
            picDung2.Visible = false;
            picDung3.Visible = false;
            picDung4.Visible = false;
            picDung5.Visible = false;
            picDung6.Visible = false;
            picDung7.Visible = false;


            picSai1.Visible = false;
            picSai2.Visible = false;
            picSai3.Visible = false;
            picSai4.Visible = false;
            picSai5.Visible = false;
            picSai6.Visible = false;
            picSai7.Visible = false;

            khauHieuDung1.Visible = false;
            KhauhieuDung2.Visible = false;
            KhauhieuDung3.Visible = false;
            KhauhieuDung4.Visible = false;
            KhauhieuDung5.Visible = false;
            KhauhieuDung6.Visible = false;
            KhauhieuDung7.Visible = false;

            KhauhieuSai1.Visible = false;
            KhauhieuSai2.Visible = false;
            KhauhieuSai3.Visible = false;
            KhauhieuSai4.Visible = false;
            KhauhieuSai5.Visible = false;
            KhauhieuSai6.Visible = false;
            KhauhieuSai7.Visible = false;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (thoiGianHienTai > 0)
            {
                thoiGianHienTai--;
                progressBar1.Value = 100 / 10 * thoiGianHienTai;

            }
            else
            {
             
                if (HetGio != null)
                {
                    HetGio(this, null);
                }
            }
            lblTime.Text = thoiGianHienTai + "";
        }

        public void SaiCauNay(int CauHoiHienTai)
        {
            SoundPlayer playersai = new SoundPlayer(@"Sound\false.wav");
            playersai.Play();
            switch (CauHoiHienTai)
            {
                case 1:
                    picCauHoi1.BackgroundImage = imageList1.Images[2];
      
                    break;
                case 2:
                    picCauHoi2.BackgroundImage = imageList1.Images[2];
                 
                    break;
                case 3:
                    picCauHoi3.BackgroundImage = imageList1.Images[2];
                    break;
                case 4:
                    picCauHoi4.BackgroundImage = imageList1.Images[2];
                    break;
                case 5:
                    picCauHoi5.BackgroundImage = imageList1.Images[2];
                    break;
                case 6:
                    picCauHoi6.BackgroundImage = imageList1.Images[2];
                    break;
                case 7:
                    picCauHoi7.BackgroundImage = imageList1.Images[2];
                    break;
            }
            timer1.Stop();
            timer2.Start();
            soCauDungLienTiep = 0;
            soCauSaiLienTiep++;
            if (soCauSaiLienTiep == 1)
            {
                KhauhieuSai1.Visible = true;
            }
            else if (soCauSaiLienTiep == 2)
            {
                KhauhieuSai2.Visible = true;
            }
            else if (soCauSaiLienTiep == 3)
            {
                KhauhieuSai3.Visible = true;
            }
            else if (soCauSaiLienTiep == 4)
            {
                KhauhieuSai4.Visible = true;
            }
            else if (soCauSaiLienTiep == 5)
            {
                KhauhieuSai5.Visible = true;
            }
            else if (soCauSaiLienTiep == 6)
            {
                KhauhieuSai6.Visible = true;
            }
            else if (soCauSaiLienTiep == 7)
            {
                KhauhieuSai7.Visible = true;
            }
            soCauSai++;
            if (soCauSai == 1)
            {
                picSai1.Visible = true;
              
            }
            else if (soCauSai == 2)
            {

                picSai2.Visible = true;
                
            }
            else if (soCauSai == 3)
            {
                picSai3.Visible = true;
                
            }
            else if (soCauSai == 4)
            {
                picSai4.Visible = true;
            
            }
            else if (soCauSai == 5)
            {
                picSai5.Visible = true;
                
            }
            else if (soCauSai == 6)
            {
                picSai6.Visible = true;
            
            }
            else if (soCauSai == 7)
            {
                picSai7.Visible = true;
              
            }

        }


        private void timer2_Tick(object sender, EventArgs e)
        {
            //if (thoiGianHienTai == 0)
            //{
            timer2.Stop();
            if (LoadCauHoiMoi != null)
            {
                comboDiem = 0;
                picDung1.Visible = false;
                picDung2.Visible = false;
                picDung3.Visible = false;
                picDung4.Visible = false;
                picDung5.Visible = false;
                picDung6.Visible = false;
                picDung7.Visible = false;


                picSai1.Visible = false;
                picSai2.Visible = false;
                picSai3.Visible = false;
                picSai4.Visible = false;
                picSai5.Visible = false;
                picSai6.Visible = false;
                picSai7.Visible = false;

                khauHieuDung1.Visible = false;
                khauHieuDung1.Visible = false;
                KhauhieuDung2.Visible = false;
                KhauhieuDung3.Visible = false;
                KhauhieuDung4.Visible = false;
                KhauhieuDung5.Visible = false;
                KhauhieuDung6.Visible = false;
                KhauhieuDung7.Visible = false;

                KhauhieuSai1.Visible = false;
                KhauhieuSai2.Visible = false;
                KhauhieuSai3.Visible = false;
                KhauhieuSai4.Visible = false;
                KhauhieuSai5.Visible = false;
                KhauhieuSai6.Visible = false;
                KhauhieuSai7.Visible = false;

                LoadCauHoiMoi(this, null);
            }

        }
        int comboDiem;

        public void DungCauNay(int CauHoiHienTai)
        {
            SoundPlayer playerdung = new SoundPlayer(@"Sound\true.wav");
            playerdung.Play();
            Diem += 100;
            soCauSaiLienTiep = 0;
            switch (CauHoiHienTai)
            {
                case 1:
                    picCauHoi1.BackgroundImage = imageList1.Images[1];
                    break;
                case 2:
                    picCauHoi2.BackgroundImage = imageList1.Images[1];
                    break;
                case 3:
                    picCauHoi3.BackgroundImage = imageList1.Images[1];
                    break;
                case 4:
                    picCauHoi4.BackgroundImage = imageList1.Images[1];
                    break;
                case 5:
                    picCauHoi5.BackgroundImage = imageList1.Images[1];
                    break;
                case 6:
                    picCauHoi6.BackgroundImage = imageList1.Images[1];
                    break;
                case 7:
                    picCauHoi7.BackgroundImage = imageList1.Images[1];
                    break;
            }
            khauHieuDung1.Visible = true;
            soCauDung++;
            soCauDungLienTiep++;
            if (soCauDungLienTiep == 1)
            {
                picDung1.Visible = true;
            }
            else if (soCauDungLienTiep == 2)
            {
                picDung2.Visible = true;
                comboDiem = 5;
                KhauhieuDung2.Visible = true;
            }
            else if (soCauDungLienTiep == 3)
            {
                picDung3.Visible = true;
                comboDiem = 10;
                KhauhieuDung3.Visible = true;
            }
            else if (soCauDungLienTiep == 4)
            {
                picDung4.Visible = true;
                comboDiem = 15;
                KhauhieuDung4.Visible = true;
            }
            else if (soCauDungLienTiep == 5)
            {
                picDung5.Visible = true;
                comboDiem = 20;
                KhauhieuDung5.Visible = true;
            }
            else if (soCauDungLienTiep == 6)
            {
                picDung6.Visible = true; 
                comboDiem = 25;
                KhauhieuDung6.Visible = true;
            }
            else if (soCauDungLienTiep == 7)
            {
                picDung7.Visible = true;
                comboDiem = 30;
                KhauhieuDung7.Visible = true;
            }
            timer1.Stop();
            timer2.Start();
            timer3.Start();
            lblDiemSo.Text = Diem.ToString();

        }

        public void Restart()
        {
            thoiGianHienTai = 10;
            lblTime.Text = "10";
            progressBar1.Value = 100;
            timer1.Start();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            if (thoiGianHienTai == 0)
            {
                timer3.Stop();
                timer4.Start();
            }
            else if(thoiGianHienTai>0)
            {
                thoiGianHienTai--;
                lblTime.Text = thoiGianHienTai.ToString();
                progressBar1.Value = 100 / 10 * thoiGianHienTai;
                Diem += 1;
                lblDiemSo.Text = Diem.ToString();
            }
        }

        private void timer4_Tick(object sender, EventArgs e)
        {
            if (comboDiem == 0)
            {
                timer4.Stop();
            }
            else
            {
                comboDiem--;
                Diem += 1;
                lblDiemSo.Text = Diem.ToString();
                
            }
        }
    }
}
